/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presentacion;

import datos.guardararchivo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;

import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;
import logica.cliente.Cliente;
import logica.cliente.Usuario;

/**
 *
 * @author Y.A.R.A
 */
public class Chat extends javax.swing.JFrame {

    private Cliente cliente =null;
    private DefaultListModel listModel = new DefaultListModel();
     private Usuario usuario;
    private ArrayList<String> mensajesescritos;
    private InetAddress direccion ;
    private boolean soyservidor;
    /**
     * Creates new form Chat
     */
    public Chat() {
        initComponents();
        cliente = new Cliente();
        usuario = new Usuario();
        //inicializo todo
        JTPchat.setEnabled(false);
        try {
            direccion = InetAddress.getByName(obtenermidireccionip());
        } catch (UnknownHostException ex) {
            Logger.getLogger(Chat.class.getName()).log(Level.SEVERE, null, ex);
        }
        JTFUsuario.setText(direccion.getHostName());
        JTFSala.setText(" ");
        //si no eres servidor se deshabilitan varios componentes
        if (!soyservidor()){
        JSPListaUsuarios.setVisible(false);
        JLListaUsuarios.setVisible(false);
        JLConectados.setVisible(false);
        JBEliminar.setVisible(false);
        JMMensajeglobal.setVisible(false);
        soyservidor=false;
        //this.setSize(626, 396);
        this.setSize(516, 396);}else{
            //si eres servidor se quedan habilitado los elementos
            soyservidor=true;
            JLListaUsuarios.setModel(listModel);
            listModel.addElement("");
            this.setSize(626, 396);
       

        }
    }
    
    public void convertirservidor()
    {
        this.setSize(626, 396);
        JSPListaUsuarios.setVisible(true);
        JLListaUsuarios.setVisible(true);
        JLConectados.setVisible(true);
        JBEliminar.setVisible(true);
        JMMensajeglobal.setVisible(true);
        soyservidor=true;
        llenarlistacontactos(JTFSala.getText());
        //this.setSize(626, 396);
    }
    
    public String obtenermidireccionip(){
      String ip =null;  
      try {
            NetworkInterface ni = NetworkInterface.getByName("eth0");
             Enumeration<InetAddress> inetAddresses =  ni.getInetAddresses();


             while(inetAddresses.hasMoreElements()) {
                 InetAddress ia = inetAddresses.nextElement();
                 if(!ia.isLinkLocalAddress()) {
                     System.out.println("IP: " + ia.getHostAddress());
                     ip=ia.getHostAddress();
                 }
             }
        } catch (SocketException ex) {
            Logger.getLogger(guardararchivo.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ip;
  }
    
    public boolean soyservidor()
    {
        File f = new File( "src/Archivos/Cliente/ipservidorprincipal.txt" );
        BufferedReader entrada;
        String linea="";
        try {
            entrada = new BufferedReader( new FileReader( f ) );
                    //lee las ip de los clientes para reenviar el mensaje
       // String direccion = InetAddress.getLocalHost().getHostAddress();
        while(entrada.ready()){
        linea = entrada.readLine();
        System.out.println("Servidor Principal : "+linea);
        
        }
        
        if (linea.equals(direccion.getHostAddress())){return true;}else{return false;}
        
        } catch (IOException ex) {
            Logger.getLogger(Cliente.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
        
        
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        JTPChatVista = new javax.swing.JTextPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        JTPchat = new javax.swing.JTextPane();
        JSPListaUsuarios = new javax.swing.JScrollPane();
        JLListaUsuarios = new javax.swing.JList();
        JBEliminar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        JTFSala = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        JTFUsuario = new javax.swing.JTextField();
        JLConectados = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        JMSalas = new javax.swing.JMenu();
        JMISala1 = new javax.swing.JMenuItem();
        JMISala2 = new javax.swing.JMenuItem();
        JMISala3 = new javax.swing.JMenuItem();
        JMISala4 = new javax.swing.JMenuItem();
        JMMensajeglobal = new javax.swing.JMenu();
        JMIEscribir = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(626, 396));
        setResizable(false);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setAutoscrolls(true);
        jScrollPane1.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N

        JTPChatVista.setEditable(false);
        JTPChatVista.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        JTPChatVista.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        JTPChatVista.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        JTPChatVista.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        JTPChatVista.setEnabled(false);
        JTPChatVista.setSelectedTextColor(new java.awt.Color(0, 0, 0));
        JTPChatVista.setSelectionColor(new java.awt.Color(0, 0, 0));
        jScrollPane1.setViewportView(JTPChatVista);

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setRequestFocusEnabled(false);

        JTPchat.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        JTPchat.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N
        JTPchat.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTPchatKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                JTPchatKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(JTPchat);

        JLListaUsuarios.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        JSPListaUsuarios.setViewportView(JLListaUsuarios);

        JBEliminar.setText("Eliminar");
        JBEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBEliminarActionPerformed(evt);
            }
        });

        jLabel1.setText("Sala :");

        JTFSala.setEditable(false);
        JTFSala.setText("jTextField1");

        jLabel2.setText("Usuario :");

        JTFUsuario.setEditable(false);
        JTFUsuario.setText("jTextField2");
        JTFUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JTFUsuarioActionPerformed(evt);
            }
        });

        JLConectados.setText("Conectados");

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        JMSalas.setText("Salas de Chat");

        JMISala1.setText("Sala 1");
        JMISala1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMISala1ActionPerformed(evt);
            }
        });
        JMSalas.add(JMISala1);

        JMISala2.setText("Sala 2");
        JMISala2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMISala2ActionPerformed(evt);
            }
        });
        JMSalas.add(JMISala2);

        JMISala3.setText("Sala 3");
        JMISala3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMISala3ActionPerformed(evt);
            }
        });
        JMSalas.add(JMISala3);

        JMISala4.setText("Sala 4");
        JMISala4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMISala4ActionPerformed(evt);
            }
        });
        JMSalas.add(JMISala4);

        jMenuBar1.add(JMSalas);

        JMMensajeglobal.setText("Mensaje Global");
        JMMensajeglobal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMMensajeglobalActionPerformed(evt);
            }
        });

        JMIEscribir.setText("Escribir");
        JMIEscribir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIEscribirActionPerformed(evt);
            }
        });
        JMMensajeglobal.add(JMIEscribir);

        jMenuBar1.add(JMMensajeglobal);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(JTFSala, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(33, 33, 33)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JTFUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(278, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
                            .addComponent(jScrollPane2))
                        .addGap(18, 18, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(JSPListaUsuarios)
                                .addComponent(JBEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                            .addComponent(JLConectados, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(19, 19, 19))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(JTFSala, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(JTFUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(JLConectados, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(JSPListaUsuarios, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(JBEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(56, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JTPchatKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTPchatKeyPressed

        if (evt.getKeyCode()==10)
        {

            if (evt.getKeyCode()==10)
        {
            
            
            cliente= new Cliente();
            usuario = new Usuario();
            usuario.setDireccionIP(direccion.getHostAddress());
            usuario.setNombre(JTFUsuario.getText());
            usuario.setPuerto(7654);
            usuario.setMensaje(JTPchat.getText());
            usuario.setSala(Integer.parseInt(JTFSala.getText()));
           // usuario=new Usuario(JTFUsuario.getText(),JTPchat.getText(),direccion.getHostAddress(),7654,Integer.parseInt(JTFSala.getText()));
           // cliente.EnviarMensaje(usuario);
          //  mostrarmensajes();
           
            //cliente = new Cliente();
            cliente.EnviarMensaje(usuario);
           // mostrarmensajes();
            JTPchat.setText("");
           
        }
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_JTPchatKeyPressed

    public void mostrarmensajes(Usuario usuario)
    {       
        int contador=0;
        //JTPChatVista.setText("");
        JTPChatVista.setText(JTPChatVista.getText()+usuario.getNombre()+" : "+usuario.getMensaje());
        JTPChatVista.setText(JTPChatVista.getText()+"\n");
        jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
    }
    
    public void mostrarmensaje2(Usuario usuario)
    {       
        int contador=0;
        //JTPChatVista.setText("");
        JTPChatVista.setText(JTPChatVista.getText()+ usuario.getMensaje());
        JTPChatVista.setText(JTPChatVista.getText()+"\n");
        jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
    }
    
    private void JTPchatKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTPchatKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_JTPchatKeyTyped

    private void JMISala1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMISala1ActionPerformed
             
         
            JTFUsuario.setText(direccion.getHostName());
            
            if(" ".equals(JTFSala.getText())){
            JTFSala.setText("1"); 
            JTPchat.setEnabled(true);
            
            }
            usuario = new Usuario();
            usuario.setDireccionIP(direccion.getHostAddress());
            usuario.setSala(Integer.parseInt(JTFSala.getText()));
            cliente.salirdesala(usuario);
            JTFSala.setText("1"); 
            usuario.setSala(Integer.parseInt(JTFSala.getText()));
            System.out.println("JMISala1 Usuario : "+usuario.getDireccionIP()+" "+usuario.getSala());
             JTPChatVista.setText("");
            cliente.entraraunasala(usuario);
           
        if (soyservidor){
        llenarlistacontactos("sala1")  ;}
              
              
              // TODO add your handling code here:
    }//GEN-LAST:event_JMISala1ActionPerformed

    private void JTFUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JTFUsuarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_JTFUsuarioActionPerformed

    private void JMISala2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMISala2ActionPerformed
         
        JTFUsuario.setText(direccion.getHostName());
        usuario = new Usuario();
            if(" ".equals(JTFSala.getText()))
            {
                
            JTFSala.setText("2");
            JTPchat.setEnabled(true);
            
         }
             usuario.setDireccionIP(direccion.getHostAddress());
            System.out.println("sala : "+JTFSala.getText());
            usuario.setSala(Integer.parseInt(JTFSala.getText()));
            
            System.out.println("sala : "+usuario.getSala());
         cliente.salirdesala(usuario);
         JTFSala.setText("2");
         usuario.setSala(Integer.parseInt(JTFSala.getText()));
          JTPChatVista.setText("");
          cliente.entraraunasala(usuario);
          
        if (soyservidor){
        llenarlistacontactos("sala2")  ;} // TODO add your handling code here:
    }//GEN-LAST:event_JMISala2ActionPerformed

    private void JMISala3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMISala3ActionPerformed
        
        JTFUsuario.setText(direccion.getHostName());
        
           if(" ".equals(JTFSala.getText())){
               JTFSala.setText("3");
               JTPchat.setEnabled(true);
               }
           usuario = new Usuario();
            usuario.setDireccionIP(direccion.getHostAddress());
            usuario.setSala(Integer.parseInt(JTFSala.getText()));
         cliente.salirdesala(usuario);
           JTFSala.setText("3");
         usuario.setSala(Integer.parseInt(JTFSala.getText()));
          JTPChatVista.setText("");
            cliente.entraraunasala(usuario);
           
        if (soyservidor){
        llenarlistacontactos("sala3")  ;} // TODO add your handling code here:
    }//GEN-LAST:event_JMISala3ActionPerformed

    private void JMISala4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMISala4ActionPerformed
        
        JTFUsuario.setText(direccion.getHostName());
        
           if(" ".equals(JTFSala.getText())){
               JTFSala.setText("4");
               JTPchat.setEnabled(true);
               }
           usuario = new Usuario();
            usuario.setDireccionIP(direccion.getHostAddress());
            usuario.setSala(Integer.parseInt(JTFSala.getText()));
         cliente.salirdesala(usuario);
         JTFSala.setText("4");
         usuario.setSala(Integer.parseInt(JTFSala.getText()));
         
          JTPChatVista.setText("");
            cliente.entraraunasala(usuario);
            
        if (soyservidor){
        llenarlistacontactos("sala4")  ;}// TODO add your handling code here:
    }//GEN-LAST:event_JMISala4ActionPerformed

    private void JMMensajeglobalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMMensajeglobalActionPerformed
        
        // TODO add your handling code here:
    }//GEN-LAST:event_JMMensajeglobalActionPerformed

    private void JMIEscribirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIEscribirActionPerformed
        MensajeGlobal mensaje= new MensajeGlobal();
        mensaje.setVisible(true);// TODO add your handling code here:
    }//GEN-LAST:event_JMIEscribirActionPerformed

    private void JBEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBEliminarActionPerformed
         usuario = new Usuario();
         String usua=null ;
        try {
            
          usua= InetAddress.getByName(JLListaUsuarios.getSelectedValue().toString()).getHostAddress();
        } catch (UnknownHostException ex) {
            Logger.getLogger(Chat.class.getName()).log(Level.SEVERE, null, ex);
        }
            usuario.setDireccionIP(usua);
            usuario.setSala(Integer.parseInt(JTFSala.getText()));
            System.out.println("se va a eliminar a :"+JLListaUsuarios.getSelectedValue()); 
            cliente.salirdesala(usuario);
            llenarlistacontactos("sala"+JTFSala.getText());
            cliente.borrarinfodepantalla(usuario);
               // TODO add your handling code here:
    }//GEN-LAST:event_JBEliminarActionPerformed

    public void borrarinformacion()
    {
        JTFSala.setText(" ");
        JTPChatVista.setText("");
        JTPChatVista.setText("El Servidor lo Saco de la Sala :( ");
        JTPchat.setEnabled(false);
    }
    
    public void llenarlistacontactos(String sala) 
    {
        System.out.println(sala.equals("sala"+JTFSala.getText()));
        if (sala.equals("sala"+JTFSala.getText())){
        listModel.clear();
        try {
            String Salaip = null;
            switch(sala){
          case "sala1":
             Salaip="ipsala1.txt";
             break;
          case "sala2":
              Salaip="ipsala2.txt";
             break;
              case "sala3":
              Salaip="ipsala3.txt";
             break;
                  case "sala4":
              Salaip="ipsala4.txt";
             break;
          }
            
            File f = new File( "src/Archivos/Servidor/"+Salaip );
            BufferedReader entrada;
            entrada = new BufferedReader( new FileReader( f ) );
            String linea;
            //lee las ip de los clientes para reenviar el mensaje
           
            while(entrada.ready()){
                try {
                    linea = entrada.readLine();
                    System.out.println(linea);
                    if (!linea.equals(obtenermidireccionip())){
                    listModel.addElement(InetAddress.getByName(linea).getHostName());}
                    
                    //JLListaUsuarios.
                } catch (IOException ex) {
                    Logger.getLogger(Chat.class.getName()).log(Level.SEVERE, null, ex);
                }
                  
            }
        } catch (IOException ex) {
            Logger.getLogger(Chat.class.getName()).log(Level.SEVERE, null, ex);
        }    
        
        }
        
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Chat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Chat().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JBEliminar;
    private javax.swing.JLabel JLConectados;
    private javax.swing.JList JLListaUsuarios;
    private javax.swing.JMenuItem JMIEscribir;
    private javax.swing.JMenuItem JMISala1;
    private javax.swing.JMenuItem JMISala2;
    private javax.swing.JMenuItem JMISala3;
    private javax.swing.JMenuItem JMISala4;
    private javax.swing.JMenu JMMensajeglobal;
    private javax.swing.JMenu JMSalas;
    private javax.swing.JScrollPane JSPListaUsuarios;
    private javax.swing.JTextField JTFSala;
    private javax.swing.JTextField JTFUsuario;
    private javax.swing.JTextPane JTPChatVista;
    private javax.swing.JTextPane JTPchat;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
}
